<div class="main-content" id="main-content">
	<div class="sub-content">
		<div class="top-header">
			<h1>User Profile</h1>
		</div>
		<form id="signupForm" name="signupForm"  method="post" action="/admin/updateprofile">
			<div class="adding_list">
				<label>User Name:</label>
				<input  type="text" id="uname" value="<? if(isset($this->user_details->username)){echo $this->user_details->username;}?>" name="uname" placeholder="Full Name"/>&nbsp;&nbsp;&nbsp;<span style="color:red" id="erroruname"></span>
			</div>
			<div class="adding_list">
				<label>Company name:</label>
				<input  type="text" id="cname" name="cname" placeholder="Company Name" value="<? if(isset($this->user_details->company_name)){echo $this->user_details->company_name;}?>"/>&nbsp;&nbsp;&nbsp;<span style="color:red" id="errorcname"></span>
			</div>
			<div class="adding_list">
				<label>Company contact number:</label>
				<input  type="text" id="ccnumber" name="ccnumber" placeholder="Company Contact Number" value="<? if(isset($this->user_details->company_contact_number)){echo $this->user_details->company_contact_number;}?>"/>&nbsp;&nbsp;&nbsp;<span style="color:red" id="errorccnumber"></span>
			</div>	
			<div class="adding_list">
				<label>Email:</label>
				<input readonly="readonly"  type="text" id="email" name="email" placeholder="Email" value="<? if(isset($this->user_details->email)){echo $this->user_details->email;}?>"/>
				&nbsp;&nbsp;&nbsp;</span><span style="color:red" id="erroremail"></span>
			</div>		
			<div class="adding_list">
				<label>Phone Number:</label>
				<input  type="text" id="pnumber" name="pnumber" placeholder="Email" value="<? if(isset($this->user_details->phone)){echo $this->user_details->phone;}?>"/>
				&nbsp;&nbsp;&nbsp;<span style="color:red" id="errorpnumber"></span>
			</div>	
			<div class="adding_list">
				<label>Country Name:</label>
				<div class="select_box">
					<select name="country" id="country">
						<option value="">-Select a country</option>	
						<?php if(isset($this->countries) && count($this->countries)>0){foreach($this->countries as $countries){ ?>
						<? if($this->user_details->country==$countries->country_id){?>
							<option value="<? echo $countries->country_id;?>" selected="selected"><? echo $countries->nicename;?></option>
						<?}else{?>
							<option value="<? echo $countries->country_id;?>"><? echo $countries->nicename;?></option>
						<?}}}?>	
					</select>&nbsp;&nbsp;&nbsp;<span style="color:red" id="errorcountry"></span>
				</div>
			</div>	
			<div class="adding_list">
				<label>State Name:</label>
				<div class="select_box">
					<select name="state" id="state">
						<option value="">-Select a state</option>	
						<?php if(isset($this->states) && count($this->states)>0){foreach($this->states as $states){ ?>
						<? if($this->user_details->state==$states->state_id){?>
						<option value="<? echo $states->state_id;?>" selected="selected"><? echo $states->state_name;?></option>
						<?}else{?>
						<option value="<? echo $states->state_id;?>"><? echo $states->state_name;?></option>
						<?}}}?>	
					</select>&nbsp;&nbsp;&nbsp;<span style="color:red" id="errorstate"></span>
				</div>
			</div>
			<div class="adding_list">
				<label>City:</label>
					<input  type="text" id="city" name="city" value="<? if(isset($this->user_details->city)){echo $this->user_details->city;}?>" placeholder="Please enter city"/>
					&nbsp;&nbsp;&nbsp;<span style="color:red" id="errorcity"></span>
			</div>	
			<div class="adding_list">
				<label>Address:</label>
					<textarea  id="address" name="address" ><? if(isset($this->user_details->address)){echo $this->user_details->address;}?></textarea>
					&nbsp;&nbsp;&nbsp;<span style="color:red" id="erroraddress"></span>
			</div>	
			<div class="adding_list">
				<label>Pincode Number:</label>
					<input  type="text" id="pcode" name="pcode" placeholder="Please enter pincode" value="<? if(isset($this->user_details->pincode)){echo $this->user_details->pincode;}?>"/>
					&nbsp;&nbsp;&nbsp;<span style="color:red" id="errorpcode"></span>
			</div>
			<div class="adding_list">
				<label>Type of user:</label>
				<div class="select_box">
					<select name="utype" id="utype">					
						<option value="">-Select a user type</option>
						<? if(isset($_SESSION['superadmin']['user_id']) && $_SESSION['superadmin']['user_id']!=""){?>
							<? if(isset($this->user_details->type_of_user) && $this->user_details->type_of_user=='admin'){?>
							<option value="admin" selected="selected">Admin</option>										
							<option value="user">User/Company</option>	
							<?}else if(isset($this->user_details->type_of_user) && $this->user_details->type_of_user=='user'){?>
							<option value="admin">Admin</option>										
							<option value="user" selected="selected">User/Company</option>	
							<?}else{?>
							<option value="admin">Admin</option>										
							<option value="user" >User/Company</option>
							<?}?>
						<?}else if(isset($_SESSION['admin']['user_id']) && $_SESSION['admin']['user_id']!=""){
							if(isset($this->user_details->type_of_user) && $this->user_details->type_of_user=='user'){?>
								<option value="user" selected="selected">User/Company</option>	
							<?}else{?>
								<option value="user" >User/Company</option>
							<?}?>
						<?}?>
					</select>
				</div>&nbsp;&nbsp;&nbsp;<span style="color:red" id="errorusertype"></span>
			</div>	
			
			<div class="adding_list">
				<div class="botton_btns">
					<ul>
						<li><a  id="reg_button" onclick="return validate();" class="registerBtn"><button>Submit</button></a></li>
						<li><button href="#">Back</button></li>
					</ul>
				</div>
			</div>		
			<span style="color:red" id="regAuthmail"></span>
			<input type="hidden" id="hiduserid" name="hiduserid" value="<? if(isset($this->user_details->user_id)){echo $this->user_details->user_id;}?>">
		</form>
	</div>
</div>
<script type="text/javascript">
   $("a").click(function(){
		$("#User").html($(this).text());		
	});
	function validate(){
		var flag=true;	
		var emailcheck=$('#email').val();
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var letters = /^[a-zA-Z ]*$/; 
		var numbers = /^[0-9]+$/;
		var username=$('#uname').val();
		var companyname=$('#cname').val();
		var companycontactnumber=$('#ccnumber').val();
		var pnumber=$('#pnumber').val();
		var country=$('#country').val();
		var state=$('#state').val();
		var city=$('#city').val();
		var address=$('#address').val();
		var pincode=$('#pcode').val();		
		if(username==""){
			$('#erroruname').html('Required');	
			flag=false;
		}else if(!username.match(letters)){
			$('#erroruname').html('');
			$("#erroruname").html("Characters only");
			flag=false;
		}else{
			$('#erroruname').html('');
		}
		if(companycontactnumber!=""){
		 if(!companycontactnumber.match(numbers)){
			$('#errorccnumber').html('numbers only');
			flag=false;
		}else if(companycontactnumber.length<10 || companycontactnumber.length>10 ){
			$('#errorccnumber').html('valid phonenumber');
			flag=false;
		}}else{
			$('#errorccnumber').html('');
		}
		if(pnumber==""){
			$('#errorpnumber').html('Required');
			flag=false;
		}else if(!pnumber.match(numbers)){
			$('#errorpnumber').html('numbers only');
			flag=false;
		}else if(pnumber.length<10 || pnumber.length>10 ){
			$('#errorpnumber').html('valid phonenumber');
			flag=false;
		}else{
			$('#errorpnumber').html('');
		}if(country==""){
			$('#errorcountry').html('Required');
			flag=false;
		}else{
			$('#errorcountry').html('');
		}
		if(state==""){
			$('#errorstate').html('Required');
			flag=false;
		}else{
			$('#errorstate').html('');
		}
		if(city==""){
			$('#errorcity').html('Required');
			flag=false;
		}else{
			$('#errorcity').html('');
		}
		if(address==""){
			$('#erroraddress').html('Required');
			flag=false;
		}else{
			 $('#erroraddress').html('');
		}
		if(pincode==""){
			$('#errorpcode').html('Required');	
			flag=false;
		}else if(!pincode.match(numbers)){
			$('#errorpcode').html('numbers only');	
			flag=false;
		}else{
			$('#errorpcode').html('');
		}
		var usertype=$('#utype').val();
       
	   if(usertype==""){
	    $('#errorusertype').html('Required');	
		   flag=false;
		}else{
			$('#errorusertype').html('');	
		}
		if(flag==false){ 
			return false;
		}else{		
			$("#signupForm").submit();
		}	
	}
	$("#country").change(function(){ 		
		var countryid=$("#country").val();	
		$.ajax({
			type:	'POST',
			url:   	'/users/get-states',
			data:	{countryid:countryid},
			success: function(data){
				if(data.output=='success'){ 				
					$("#state").html(data.statenames);
				}							
			}
		});
	});
</script>